package ch.bfh.java.directorysynchronizer.presentation.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;

import ch.bfh.java.directorysynchronizer.presentation.items.Workbench;

public class TargetfileDirectoryButtonListener implements ActionListener
{

	private Workbench workbench;
	private JFileChooser chooser;

	public TargetfileDirectoryButtonListener(Workbench wb)
	{

		this.workbench = wb;
		this.chooser = new JFileChooser();

	}

	@Override
	public void actionPerformed(ActionEvent arg0)
	{

		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		chooser.setApproveButtonText("sync this directory");
		chooser.setDialogTitle("Target directory");
		chooser.setCurrentDirectory(new File("C:\\"));

		if(chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
		{
			workbench.setTargetDirectoryFile(chooser.getSelectedFile());
			workbench.getTargetDirectoryTextfield().setText(
			        workbench.getTargetDirectoryFile().getAbsolutePath());
		}

	}
}
